package com.feng.controller;

import com.feng.entity.RestResponse;
import com.feng.entity.vo.AddRoleVo;
import com.feng.entity.vo.RoleListVo;
import com.feng.entity.vo.UpdateRoleStatusReqVo;
import com.feng.service.RoleService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/role")
public class RoleController {

    final
    RoleService roleService;

    public RoleController(RoleService roleService) {
        this.roleService = roleService;
    }

    //account页面的
    @PreAuthorize("@ps.hasPermission('system:role:query')")
    @GetMapping("/listAllRole")
    public RestResponse listAllRole(){
        return roleService.listAllRole();
    }

    //role页面的
    @PreAuthorize("@ps.hasPermission('system:role:query')")
    @PostMapping("/listAllRole")
    public RestResponse listPageAllRole(@RequestBody RoleListVo roleList){
        return roleService.listPageAllRole(roleList);
    }

    @PreAuthorize("@ps.hasPermission('system:role:edit')")
    @PutMapping("/updateStatus")
    public RestResponse updateStatus(@RequestBody UpdateRoleStatusReqVo updateRoleStatus){
        return roleService.updateStatus(updateRoleStatus);
    }

    @PreAuthorize("@ps.hasPermission('system:role:add')")
    @PostMapping("/addRole")
    public RestResponse addRole(@RequestBody AddRoleVo addRole){
        return roleService.addRole(addRole);
    }

    @PreAuthorize("@ps.hasPermission('system:role:query')")
    @GetMapping("/getRoleById/{id}")
    public RestResponse  getRoleById(@PathVariable Long id){
        return roleService.getRoleById(id);
    }

    @PreAuthorize("@ps.hasPermission('system:role:edit')")
    @PutMapping("/updateRole")
    public RestResponse  updateRole(@RequestBody AddRoleVo addRole){
        return roleService.updateRole(addRole);
    }

    @PreAuthorize("@ps.hasPermission('system:role:remove')")
    @DeleteMapping("/deleteRole/{id}")
    public RestResponse deleteRole(@PathVariable Long id){
        return roleService.deleteRole(id);
    }

    @PreAuthorize("@ps.hasPermission('system:role:remove')")
    @DeleteMapping("/delBatchRole/{ids}")
    public RestResponse delBatchRole(@PathVariable List<Long> ids){
        return roleService.delBatchRole(ids);
    }

    @PreAuthorize("@ps.hasPermission('system:role:export')")
    @GetMapping("/export")
    public void export(HttpServletResponse response){
        roleService.export(response);
    }
}
